Java Variables:-
Variables are used for storing the data values.
Various types of variables are:
- String
- int
- float
- char
- Boolean
Declaration of Variables:-
Type variable = value;
Example
String name = “Nitin”;
System.out.println (name);To Top
A parameter used in Java Program:-
- class keyword used to declare a class in java.2
- The public keyword is used to access inside the class outside the class inside the method anywhere.
- static is used when we declare any method as static. There is no need to create an object to call the static method.
- void means that it does not contain any value.
- main represents the starting point of the program.
- String args [] is used for line command.
- System.out.println is used to print the statement.
- Private Java private keyword is an access modifier. It is used to indicate that a method or variable may be accessed only in the class in which it is declared
Example’
class Student
{
public static void main (String args [])
{
System.out.println (“I Love you”);
}
}
Compile by-java Student.java
Run by- Student Java
Output;
I Love You.
Java Methods:-
- A method is a block of code which only runs when it is called.
- You can pass data, known as parameters, into a method.
- Methods are also known as a function.
- If we define the code once and use it many times.
- The method followed by parenthesis ().
- Java provides some pre-defined method such as System.out.println (). But we can also create own method.
Example;
public class Student
{
static void Mymethod()
{
System.out.println(“I am fine”);
}
public static void main(String args[])
{
Mymethod();
}
}
Output:- I am fine.
Khushi Singh
16-Mar-2025The Java programming language uses variables together with methods as its core tools to establish program behavior as well as overall functionality. A program becomes modular and reusable due to the combination of storage through variables and operation execution through methods which act on stored data.
Java programming includes variables that operate as labeled memory locations which link to particular data types. Java provides three variable types including local variables for method declarations and local scope memory allocation and instance variables as object-related elements inside class definitions outside method declarations and static variables for class-level variables requiring the static keyword declaration. Java offers two types of data variables including basic primitive elements such as int, double and boolean alongside reference elements consisting of classes and arrays.
Java programming language provides methods as distinct blocks of code where developers can implement particular functional tasks. Java includes built-in methods for output printing as
System.out.println()together with methods that developers implement to develop logical encapsulation. All methods contain one or more defined return types together with a mandatory method name but may optionally include parameters. A method absent from returning anything must declare itself using the void keyword.Effective use of method declarations alongside variables within Java programs creates better code structures that minimize multiple statements and simplify upkeep. Programming methods allow developers to achieve code reuse and variables provide efficient storage and manipulation functions for data.